package com.agy.filemanager.service.impl;

import com.agy.filemanager.common.StringUtils;
import com.agy.filemanager.entity.DcBaseRole;
import com.agy.filemanager.entity.DcBaseRoleMenu;
import com.agy.filemanager.entity.TreeModel;
import com.agy.filemanager.mapper.DcBaseRoleMenuDao;
import com.agy.filemanager.service.DcBaseRoleMenuService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Zhang Fan
 * @date 2018\8\8 0008 16:17
 * @desc 角色-菜单Service层实现类
 */
@Service
public class DcBaseRoleMenuServiceImpl implements DcBaseRoleMenuService {

    @Autowired
    DcBaseRoleMenuDao dcBaseRoleMenuDao;

    /**
     * 分页-获取角色信息
     * @param pageNum 当前页码
     * @param pageSize 每页条数
     * @return
     */
    @Override
    public Page getRoleInfo(int pageNum, int pageSize) {
        Page page = PageHelper.startPage(pageNum, pageSize);
        List<DcBaseRole> list = dcBaseRoleMenuDao.getRoleInfo();
        return page;
    }

    /**
     * 通过角色ID获取DcBaseRoleMenu实体
     * @param id 角色ID
     * @return
     */
    @Override
    public List<DcBaseRoleMenu> getInfoByRoleId(String id) {
        return dcBaseRoleMenuDao.getInfoByRoleId(id);
    }

    /**
     * 保存：角色-菜单
     * @param menuIdList 数组：菜单ID
     * @param roleId 角色ID
     */
    @Override
    public void addRoleMenuInfo(String[] menuIdList,String roleId) {
        dcBaseRoleMenuDao.deteleByRoleId(roleId);
        for (String list:menuIdList) {
            DcBaseRoleMenu dcBaseRoleMenu = new DcBaseRoleMenu();
            dcBaseRoleMenu.setId(StringUtils.getUUID());
            dcBaseRoleMenu.setRole_Id(roleId);
            dcBaseRoleMenu.setMenu_Id(list);
            dcBaseRoleMenuDao.addRoleMenuInfo(dcBaseRoleMenu);
        }
    }

    /**
     * 获取菜单树
     * @return
     */
    @Override
    public List<TreeModel> menuTreeInfo() {
        return dcBaseRoleMenuDao.menuTreeInfo();
    }
}
